#pragma once
#include <windows.h>
#include <boost\smart_ptr\shared_array.hpp>
#include <QObject>
#include <QMap>
#include <QSet>
 
class MemoryBuffer:public QObject 
{
	Q_OBJECT
public:
	MemoryBuffer(QObject * parent);
	virtual ~MemoryBuffer(void) {
	}
	bool has(UINT64 start,int len);
	char * getData( UINT64 start, UINT64 len );
	void add( UINT64 start, UINT64 len, char * target );
	float getHitRatio() {
		if (m_total)
			return (float)m_hit/m_total;
		else return 0.0;
	}
	void resetHitRatio() {
		m_total = m_hit = 0;
	}
private:
	static const int MAX_ENTRY=10000;
	int m_hit;
	int m_total;
	QMap<UINT64,int> m_off2index;
#pragma pack(push)
#pragma pack(1)
	struct STORE{
		UINT64 start;
		int len;
		char data[1024];
		STORE():start(0),len(0){}
	} m_dat[MAX_ENTRY];
#pragma pack(pop)
	QSet<int> unused;
	//QMultiMap<long,UINT64>m_time;
};
